package com.stu.day15;

import java.io.*;

/**
 * read(byte b[]),Write(byte b[],0,len)
 * try(声明对象){
 *     // 对象的关闭交给jvm完成
 *  }
 * @author zy
 * @date 2025/2/13 15:58
 */
public class IODemo2 {
    public static void main(String[] args) {

        try (InputStream in = new FileInputStream("src/com/stu/day15/demo1.png");
             OutputStream out = new FileOutputStream("src/com/stu/day15/demo1_副本.png");){

            byte[] buf = new byte[1024*3];  // 3kb的缓存区
            while (true) {
                int len = in.read(buf);  // 通过缓存区减少交互次数,大大提升效率
                if(len == -1) break;
                out.write(buf, 0, len);
            }

        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
